<!DOCTYPE html>
<html lang="zh-cn">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>什么都论坛-后台用户管理</title>
  <style>
    body {
      background: #f7f9fb;
      margin: 0;
      padding: 0;
    }

    .container {
      width: 90%;
      max-width: 1100px;
      margin: -50px auto;
      background: #fff;
      border-radius: 10px;
      box-shadow: 0 2px 12px rgba(80, 133, 203, 0.08);
      padding: 30px;
    }

    .container h2 {
      margin-top: 0;
      color: #0327b3;
      text-align: center;
      padding: 0;
      margin: 0 auto 10px;
    }

    .actions {
      margin-bottom: 20px;
      text-align: right;
    }

    .actions button {
      background: #2a4dd0;
      color: #fff;
      border: none;
      border-radius: 5px;
      padding: 8px 18px;
      font-size: 15px;
      cursor: pointer;
      transition: background 0.2s;
      margin-left: 10px;
    }

    .actions button:hover {
      background: #0327b3;
    }

    table {
      width: 100%;
      border-collapse: collapse;
      margin-top: 10px;
      background: #fff;
    }

    th,
    td {
      padding: 12px 8px;
      border-bottom: 1px solid #f0f0f0;
      text-align: center;
    }

    th {
      background: #f4f6f9;
      color: #0327b3;
      font-weight: 600;
    }

    tr:hover {
      background: #f0f6ff;
    }

    .edit-btn,
    .delete-btn {
      background: #5085cb;
      color: #fff;
      border: none;
      border-radius: 4px;
      padding: 5px 12px;
      margin: 0 3px;
      cursor: pointer;
      font-size: 14px;
      transition: background 0.2s;
    }

    .edit-btn:hover {
      background: #2a4dd0;
    }

    .delete-btn {
      background: #e74c3c;
    }

    .delete-btn:hover {
      background: #c0392b;
    }

    .avatar {
      width: 36px;
      height: 36px;
      border-radius: 50%;
      object-fit: cover;
      border: 1px solid #eee;
    }
  </style>
</head>

<body>
  <div class="container">
    <h2>用户管理</h2>
    <div class="actions">
      <button onclick="location.href='../../bbs/views/login.php'">添加用户</button>
      <button onclick="location.reload()">刷新</button>
    </div>
    <table>
      <thead>
        <tr>
          <th>ID</th>
          <th>头像</th>
          <th>用户名</th>
          <th>性别</th>
          <th>状态</th>
          <th>角色</th>
          <th>注册时间</th>
          <th>操作</th>
        </tr>
      </thead>
      <tbody>
        <?php
        require_once '../control/doUser.php';
        $users = $_SESSION['users'];
        foreach ($users as $user) {
          if ($user['role'] === 'user') {
            echo "<tr>";
            echo "<td>{$user['uId']}</td>";
            echo "<td><img src='../../bbs/image/head/{$user['head']}' class='avatar' alt='头像'></td>";
            echo "<td>{$user['uName']}</td>";
            if ($user['gender'] == 1) {
              echo "<td>女</td>";
            } else {
              echo "<td>男</td>";
            }
            if ($user['state'] == 1) {
              echo "<td style='color:green;'>登录中</td>";
            } else {
              echo "<td style='color:red;'>未登录</td>";
            }
            echo "<td>{$user['role']}</td>";
            echo "<td>{$user['regTime']}</td>";
            echo '<td><button class="edit-btn" onclick="location.href=\'./indexBms.php?action=edit&uId=' . $user['uId'] . '\'">编辑</button><button class="delete-btn" onclick="confirm(\'确认删除吗？\')?location.href=\'../control/doUser.php?del=delete&uId=' . $user['uId'] . '\':false">删除</button></td>';
            echo "</tr>";
          }
        }

        ?>


      </tbody>
    </table>
  </div>

</body>

</html>